#include "A.h"
#include <windows.h>
#include <iostream>

typedef int (*B3Func)(char*);
typedef int (*B4Func)(char*);

HINSTANCE hinstLib;
B3Func B3;
B4Func B4;

BOOL LoadBLibrary() {
    hinstLib = LoadLibrary(TEXT("B.dll"));
    if (hinstLib != NULL) {
        B3 = (B3Func)GetProcAddress(hinstLib, "B3");
        if (B3 != NULL) {
            return TRUE;
        }
    }
    return FALSE;
}

extern "C" A_API int A1(char* buff, int len) {
    if (LoadBLibrary()) {
        std::cout << "  A1 called with: " << buff << ", len=" << len << std::endl;
        return B3(buff);
    }
    return -1;
}

extern "C" A_API int A2(char* buff) {
    if (LoadBLibrary()) {
        std::cout << "  A2 called with: " << buff << std::endl;
        return B4(buff);
    }
    return -1;
}